package com.sslpay.merchant;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.sslpay.common.domain.BusinessException;
import com.sslpay.common.util.EncryptUtil;
import com.sslpay.merchant.api.MerchantService;
import com.sslpay.merchant.api.dto.MerchantDTO;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * 描述：临时token解决方案
 *
 * @author ssl
 * @create 2020/05/06 10:14
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class TokenTemp {
    @Autowired
    private MerchantService merchantService;

    @Test
    public void createTestToken() throws BusinessException {
        Long merchantId = 1257213187850268673l;
        MerchantDTO merchantDTO = merchantService.getMerchantById(merchantId);
        JSONObject token = new JSONObject();
        token.put("mobile", merchantDTO.getMobile());
        token.put("username", merchantDTO.getUsername());
        token.put("merchantId", merchantDTO.getId());
        String jwtToken = "Bearer ".concat(EncryptUtil.encodeBase64(JSON.toJSONString(token).getBytes()));
        System.out.println(jwtToken);
    }
}
